package org.caijin.springrabbitMQ.mq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Delivery;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = "demoQueue")
// 默认自动ack
public class DemoQueueConsumer2 {

    /**
     * 消息消费
     * @param message 消息
     */
    @RabbitHandler
    public void received(String msg, Channel channel,Message message) throws Exception {
        
        System.out.println("[demoQueue] received message2: " + msg);
        // 一次拿2个消息
        channel.basicQos(2);
        // ack确认deliver tag的消息
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);


    }
}
